<template>
  <div>
    <el-card>
      <!-- 表单部分 -->
      <el-form :inline="true" :model="orderFrom" class="demo-form-inline">
        <el-form-item label="订单号">
          <el-input v-model="orderFrom.orderNo" placeholder="订单号"></el-input>
        </el-form-item>
        <el-form-item label="收货人">
          <el-input
            v-model="orderFrom.consignee"
            placeholder="收货人"
          ></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="orderFrom.phone" placeholder="手机号"></el-input>
        </el-form-item>
        <el-form-item label="订单状态">
          <el-select v-model="orderFrom.orderState" placeholder="订单状态">
            <el-option label="派送中" value="派送中"></el-option>
            <el-option label="已完成" value="已完成"></el-option>
            <el-option label="已受理" value="已受理"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间范围">
          <el-date-picker
            v-model="orderFrom.date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <el-button type="primary" @click="onSubmit('s')">查询</el-button>
        </el-form-item>
      </el-form>
      <!-- 表格 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="orderNo" label="订单号" width="150">
        </el-table-column>
        <el-table-column label="下单时间" width="200px">
          <template v-slot="{ row }">
            {{ row.orderTime | format }}
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="手机号" width="150px">
        </el-table-column>
        <el-table-column prop="consignee" label="收货人"> </el-table-column>
        <el-table-column prop="deliverAddress" label="配送地址">
        </el-table-column>
        <el-table-column label="送达时间" width="200px">
          <template v-slot="{ row }">
            {{ row.deliveryTime | format }}
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="用户备注"> </el-table-column>
        <el-table-column prop="orderAmount" label="订单金额"> </el-table-column>
        <el-table-column prop="orderState" label="订单状态"> </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small"
              >查看</el-button
            >
            <el-button type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 查看内容 -->
      <el-dialog title="提示" :visible.sync="dialogVisible" width="40%">
        <div>
          <el-steps :space="200" :active="counm" finish-status="success">
            <el-step title="已受理"></el-step>
            <el-step title="派送中"></el-step>
            <el-step title="已完成"></el-step>
          </el-steps>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { orderlist, ordersearch } from '../../api/order.js'
export default {
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      counm: 1,
      orderFrom: {
        orderNo: '',
        date: '',
        phone: '',
        consignee: '',
        orderState: ''
      },
      dialogVisible: false
    }
  },
  created() {
    this.onSubmit()
  },
  methods: {
    async onSubmit(s) {
      const obj = {
        currentPage: this.currentPage,
        pageSize: this.pageSize,
        ...this.orderFrom
      }
      let result = null
      if (s) {
        obj.currentPage = 1
        obj.date = JSON.stringify(obj.date)
        result = await ordersearch(obj)
      } else {
        result = await orderlist({
          currentPage: this.currentPage,
          pageSize: this.pageSize,
          orderNo: '',
          date: '',
          phone: '',
          consignee: '',
          orderState: ''
        })
      }
      const { data, total } = result
      this.tableData = data
      this.total = total
    },

    handleClick(row) {
      const obj = {
        已受理: 1,
        派送中: 2,
        已完成: 3
      }
      this.counm = obj[row.orderState]
      this.dialogVisible = true
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.onSubmit()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.onSubmit()
    },
    fn(row) {
      console.log(row)
    }
  }
}
</script>

<style lang="less" scoped>
.demonstration {
  margin-right: 10px;
}
.el-button {
  margin-left: 10px;
}
.block {
  margin-bottom: 40px;
}
</style>
